<template>
	<view class="calendar-container">
		<!-- 左箭头 -->
		<!--<view class="arrow" @click="prevWeek">1
		</view> -->

		<!-- 日期列表 -->
		<view class="date-list">
			<view v-for="(day, index) in mainData" :key="index" class="date-item"
				:class="{ active: index === selectedIndex }" @click="selectDay(index,day)">
				<view class="">
					<view class="weekday ">{{ day.weekDay }}</view>
					<view class="date f14">{{ day.date }}</view>
				</view>
				<view class="status f14" :class="{
            'subscribed': day.orderType == '1'  || day.orderType == '2',
            'not-subscribed': day.orderType == '0',
          }">
					{{ day.orderType == '1'? '已订' : day.orderType == '2' ? '超时' : '未订' }}
				</view>
			</view>
		</view>

		<!-- 右箭头 -->
		<!-- <view class="arrow" @click="nextWeekFunc">></view> -->
	</view>
</template>

<script>
	import dayjs from 'dayjs'

	export default {
		data() {
			return {
				selectedIndex: 0,
				nextWeek: []
			}
		},
		props: {
			mainData: {
				type: Array,
				default: () => []
			},
			weekIndex: {
				type: Number,
				default: 0
			}
		},
		watch: {
			weekIndex: {
				handler(e) {
					this.selectedIndex = e
				},
			},
		},
		onShow() {
			
		},
		created() {

		},
		methods: {
			generateNextWeek(offset = 0) {
				const weekdays = ['日', '一', '二', '三', '四', '五', '六']
				const today = dayjs()
				const dayOfWeek = today.day()
				const thisMonday = today.subtract(dayOfWeek === 0 ? 6 : dayOfWeek - 1, 'day')
				const nextMonday = thisMonday.add(7 + offset * 7, 'day')

				this.nextWeek = Array.from({
					length: 5
				}, (_, i) => {
					const date = nextMonday.add(i, 'day')
					return {
						weekday: weekdays[date.day()],
						month: date.month() + 1,
						date: date.date(),
						status: i === 1 ? '已订' : '未订'
					}
				})
			},
			selectDay(index,day) {
				if (this.mainData[index].orderType == 1) return this.$modal.msg('已经订过了~')
				if (this.mainData[index].orderType == 2) return this.$modal.msg('已经超时了~')
				this.selectedIndex = index
				this.$emit('cutWeek', {index:index,day:day})
			},
			prevWeek() {
				this.weekOffset = (this.weekOffset || 0) - 1
				this.generateNextWeek(this.weekOffset)
			},
			nextWeekFunc() {
				this.weekOffset = (this.weekOffset || 0) + 1
				this.generateNextWeek(this.weekOffset)
			}
		}
	}
</script>

<style scoped lang="scss">
	.calendar-container {
		display: flex;
		align-items: center;
		/* background: white; */
		padding: 24rpx 0;
		border-radius: 8px;
		/* box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); */
		/* height: 160rpx; */
	}

	.arrow {
		font-size: 20px;
		color: #aaa;
		cursor: pointer;
		padding: 0 10px;
	}

	.date-list {
		width: 100%;
		display: flex;
		// gap: 8rpx;
		justify-content: space-between;
		// flex: 1;
		// overflow-x: auto;
	}

	.date-item {
		width: 90rpx;
		height: 140rpx;
		background: #fff;
		border-radius: 8px;
		padding: 6px;
		text-align: center;
		font-size: 12px;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		align-items: center;
		transition: 0.2s;
		color: #323232;


	}

	.date-item.active {
		background: linear-gradient(90deg, #25B982 0%, #1AB57B 100%);
		color: white;

		.weekday {
			color: #fff;
		}
	}


	.weekday {
		transition: 0.2s;
		color: #848484;
		margin-top: 4px;
		font-size: 28rpx;
	}

	.date {
		font-weight: bold;
		font-size: 33rpx;
	}

	.status {
		// margin-top: 10rpx;
		border-radius: 999px;
		// padding: 0px 6px;
		width: 70rpx;
		height: 32rpx;
		line-height: 32rpx;
		transition: 0.2s;
		font-size: 28rpx;
	}

	.status.not-subscribed {
		background: white;
		color: #fff;
		border: 1px solid #00c777;
		background-color: #00c777;
		font-size: 24rpx;
	}

	.date-item.active .status.not-subscribed {
		background: white;
		color: #00c777;
		font-size: 24rpx;
	}

	.status.subscribed {
		background: #b3b3b3;
		color: white;
		font-size: 24rpx;
	}
</style>